#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：zhcx-service-test 
@File    ：strategy_mongo_export.py
@Author  ：关依林
@Date    ：2023/12/18 14:09 
'''
from testcases.ProductGrading_Strategy.AmazonListing.dao.query_sql_method import getStrategyData
from testcases.ProductGrading_Strategy.public_dispatch_way import connectMysql, connectMongoTest


def getStrategyReport(strategyId):
    err = []
    sql = f"SELECT source_id,document_url FROM t_strategy_result_log WHERE strategy_id = {strategyId}"
    cursorStrategyTest = connectMysql("Java_centerStrategy_Test")
    res = cursorStrategyTest.execute_sql_many(sql)
    for item in res:
        sourceId = item["source_id"]
        strategyResult = getStrategyData(cursorStrategyTest, strategyId, sourceId)
        strategyExportResult = getMongoExportData(strategyId, sourceId)
        err = list(set(strategyResult) - set(strategyExportResult))
        if err:
            print(f"strategyId:{strategyId},source_id:{sourceId},数据异常...")
    return err


def getMongoExportData(strategyId, OrderSourceId):
    date = "20231214"
    mongoCursor = connectMongoTest(f"t_strategy_amazon_listing_{strategyId}_{date}")
    sql = {"source_id": OrderSourceId}
    field = {"_id": 0, "listing_id": 1}
    strategyResult = mongoCursor.select2(sql, field)
    strategyResult = [(str(i["listing_id"])) for i in strategyResult]
    return strategyResult


if __name__ == '__main__':
    print(getStrategyReport(262))
